package com.mine;

import com.google.common.base.Charsets;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnel;
import com.google.common.hash.Funnels;
import com.google.common.hash.PrimitiveSink;
import org.junit.Test;

/**
 * 优点：可以直接使用
 * 缺点：仅支持outputStream的持久化，不方便与redis结合
 *
 * @author wangtonggui
 * @version 1.0.0
 * @since 2021/09/28 17:21
 */
public class BloomFilterDemos {
  @Test
  public void bloomFilter() {
    BloomFilter<CharSequence> bloomFilter =
        BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8), 100000, 0.01);
    bloomFilter.put("1");
    bloomFilter.put("2");
    bloomFilter.put("3");
    System.out.println(bloomFilter.mightContain("3"));
    System.out.println(bloomFilter.mightContain("4"));
  }
}
